﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using java.lang;
using java.util;

namespace Game.model.@base
{
    public class ClassId
    {
        private int _id;
	    
	    public Race _race;
	   
	    private ClassId _parent;
	   
	    private ClassId _parent2;
	   
	    private ClassLevel _level;
	   
	    private ClassType _type;
	   
	    private ClassType2 _type2;
        private ClassId(int id, ClassType classType, Race race, ClassId parent, ClassLevel level, ClassType2 classType2):
            this(id, classType, race, parent, null, level, classType2)
        {
            //;
        }
        private ClassId(int id, ClassType classType, Race race, ClassId parent, ClassId parent2, ClassLevel level, ClassType2 classType2)
        {
            _id = id;
            _type = classType;
            _race = race;
            _parent = parent;
            _parent2 = parent2;
            _level = level;
            _type2 = classType2;
            Setup();
        }
        public int getId()
	    {
		    return _id;
	    }
	    public Race getRace()
	    {
		    return _race;
	    }
	    public bool isOfRace(Race race)
	    {
		    return _race == race;
	    }
	    public ClassLevel getClassLevel()
	    {
		    return _level;
	    }
        public bool isOfLevel(ClassLevel level)
	    {
		    return _level == level;
	    }
	    public ClassType getType()
	    {
		    return _type;
	    }
	    public bool isOfType(ClassType type)
	    {
		    return _type == type;
	    }
	    public ClassType2 getType2()
	    {
		    return _type2;
	    }
        public bool isMage()
	    {
		    return _type.isMagician();
	    }
	    public bool childOf(ClassId cid)
	    {
		    if ((_parent == null) && (_id < 139))
		    {
			    return false;
		    }
		    if ((_parent == cid) || (_parent2 == cid))
		    {
			    return true;
		    }
		    if (_id > 138)
		    {
		        var temp = (Map) _childClasses.get(this);
			    return temp.containsValue(cid);
		    }
		    return _parent != null && _parent.childOf(cid);
	    }
        private static long serialVersionUID = 1L;
        public Map _childClasses = new HashMap();
        
        void Setup()
        {
            _childClasses.put(ClassId.sigelKnight, EnumSet.of(ClassId.PHOENIX_KNIGHT, ClassId.HELL_KNIGHT, ClassId.EVAS_TEMPLAR, ClassId.SHILLIEN_TEMPLAR));
            _childClasses.put(ClassId.tyrrWarrior, EnumSet.of(ClassId.DUELIST, ClassId.DREADNOUGHT, ClassId.TITAN, ClassId.GRAND_KHAVATARI, ClassId.MAESTRO, ClassId.DOOMBRINGER));
            _childClasses.put(ClassId.othellRogue, EnumSet.of(ClassId.ADVENTURER, ClassId.WIND_RIDER, ClassId.GHOST_HUNTER, ClassId.FORTUNE_SEEKER));
            _childClasses.put(ClassId.yulArcher, EnumSet.of(ClassId.SAGITTARIUS, ClassId.MOONLIGHT_SENTINEL, ClassId.GHOST_SENTINEL, ClassId.TRICKSTER));
            _childClasses.put(ClassId.feohWizard, EnumSet.of(ClassId.ARCHMAGE, ClassId.SOULTAKER, ClassId.MYSTIC_MUSE, ClassId.STORM_SCREAMER, ClassId.M_SOUL_HOUND, ClassId.F_SOUL_HOUND));
            _childClasses.put(ClassId.issEnchanter, EnumSet.of(ClassId.HIEROPHANT, ClassId.SWORD_MUSE, ClassId.SPECTRAL_DANCER, ClassId.DOMINATOR, ClassId.DOOMCRYER, ClassId.JUDICATOR));
            _childClasses.put(ClassId.wynnSummoner, EnumSet.of(ClassId.ARCANA_LORD, ClassId.ELEMENTAL_MASTER, ClassId.SPECTRAL_MASTER));
            _childClasses.put(ClassId.aeoreHealer, EnumSet.of(ClassId.CARDINAL, ClassId.EVAS_SAINT, ClassId.SHILLIEN_SAINT));
        }
        public bool equalsOrChildOf(ClassId cid)
	    {
		    return (this == cid) || (childOf(cid));
	    }
        public ClassId getParent(int sex)
	    {
		    return (sex == 0) || (_parent2 == null) ? _parent : _parent2;
	    }
            public int getParentId()
	    {
		    return _parent.getId();
	    }
        public int level()
	    {
		    if (_parent == null)
		    {
			    return 0;
		    }
		    return 1 + _parent.level();
	    }
        public static readonly ClassId HUMAN_FIGHTER = new ClassId(0, ClassType.FIGHTER, Race.human, null, ClassLevel.First, null);

        public static readonly ClassId WARRIOR = new ClassId(1, ClassType.FIGHTER, Race.human, HUMAN_FIGHTER,
                                                             ClassLevel.Second, null);

        public static readonly ClassId GLADIATOR = new ClassId(2, ClassType.FIGHTER, Race.human, WARRIOR,
                                                               ClassLevel.Third, ClassType2.Warrior);

        public static readonly ClassId WARLORD = new ClassId(3, ClassType.FIGHTER, Race.human, WARRIOR, ClassLevel.Third,
                                                             ClassType2.Warrior);

        public static readonly ClassId KNIGHT = new ClassId(4, ClassType.FIGHTER, Race.human, HUMAN_FIGHTER,
                                                            ClassLevel.Second, null);

        public static readonly ClassId PALADIN = new ClassId(5, ClassType.FIGHTER, Race.human, KNIGHT, ClassLevel.Third,
                                                             ClassType2.Knight);

        public static readonly ClassId DARK_AVENGER = new ClassId(6, ClassType.FIGHTER, Race.human, KNIGHT,
                                                                  ClassLevel.Third, ClassType2.Knight);

        public static readonly ClassId ROGUE = new ClassId(7, ClassType.FIGHTER, Race.human, HUMAN_FIGHTER,
                                                           ClassLevel.Second, null);

        public static readonly ClassId TREASURE_HUNTER = new ClassId(8, ClassType.FIGHTER, Race.human, ROGUE,
                                                                     ClassLevel.Third, ClassType2.Rogue);

        public static readonly ClassId HAWKEYE = new ClassId(9, ClassType.FIGHTER, Race.human, ROGUE, ClassLevel.Third,
                                                             ClassType2.Archer);

        public static readonly ClassId HUMAN_MAGE = new ClassId(10, ClassType.MYSTIC, Race.human, null, ClassLevel.First,
                                                                null);

        public static readonly ClassId WIZARD = new ClassId(11, ClassType.MYSTIC, Race.human, HUMAN_MAGE,
                                                            ClassLevel.Second, null);

        public static readonly ClassId SORCERER = new ClassId(12, ClassType.MYSTIC, Race.human, WIZARD, ClassLevel.Third,
                                                              ClassType2.Wizard);

        public static readonly ClassId NECROMANCER = new ClassId(13, ClassType.MYSTIC, Race.human, WIZARD,
                                                                 ClassLevel.Third, ClassType2.Wizard);

        public static readonly ClassId WARLOCK = new ClassId(14, ClassType.MYSTIC, Race.human, WIZARD, ClassLevel.Third,
                                                             ClassType2.Summoner);

        public static readonly ClassId CLERIC = new ClassId(15, ClassType.PRIEST, Race.human, HUMAN_MAGE,
                                                            ClassLevel.Second, null);

        public static readonly ClassId BISHOP = new ClassId(16, ClassType.PRIEST, Race.human, CLERIC, ClassLevel.Third,
                                                            ClassType2.Healer);

        public static readonly ClassId PROPHET = new ClassId(17, ClassType.PRIEST, Race.human, CLERIC, ClassLevel.Third,
                                                             ClassType2.Enchanter);

        public static readonly ClassId ELVEN_FIGHTER = new ClassId(18, ClassType.FIGHTER, Race.elf, null,
                                                                   ClassLevel.First, null);

        public static readonly ClassId ELVEN_KNIGHT = new ClassId(19, ClassType.FIGHTER, Race.elf, ELVEN_FIGHTER,
                                                                  ClassLevel.Second, null);
    }
}
